﻿<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:vm="clr-namespace:SqlExport.ViewModel"
             xmlns:view="clr-namespace:SqlExport.View"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
             xmlns:command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF45"
             mc:Ignorable="d"
             x:Class="SqlExport.View.MessageList"
             x:Name="UserControl"
             d:DataContext="{d:DesignInstance Type=vm:MessageListViewModel, IsDesignTimeCreatable=True}"
             d:DesignWidth="640" d:DesignHeight="480">
    <DockPanel x:Name="LayoutRoot">
        <DockPanel.Resources>
            <ResourceDictionary>
                <vm:MessageListViewModel x:Key="ViewModel" />
                <DataTemplate x:Key="MessageItemTemplate">
                    <Grid Margin="0" VerticalAlignment="Top">
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="16"/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <Image Grid.ColumnSpan="1" Source="{Binding Image, Converter={StaticResource ImageToBitmapImageConverter}, Mode=OneWay}" Visibility="{Binding IsSeparator, Converter={StaticResource InverseBooleanToVisibilityConverter}, Mode=OneWay}" Stretch="None" VerticalAlignment="Top"/>
                        <TextBlock Margin="4,0,0,0" TextWrapping="Wrap" d:LayoutOverrides="Width, Height" Grid.Column="1" Text="{Binding DisplayText}" Visibility="{Binding IsSeparator, Converter={StaticResource InverseBooleanToVisibilityConverter}, Mode=OneWay}"/>
                        <Rectangle Fill="#FFF4F4F5" Height="Auto" Stroke="Black" VerticalAlignment="Bottom" Grid.Row="1" Grid.ColumnSpan="2" Visibility="{Binding IsSeparator, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}" Margin="0,2,0,3"/>
                    </Grid>
                </DataTemplate>
            </ResourceDictionary>
        </DockPanel.Resources>

        <Button x:Name="btnClear" Content="Clear" VerticalAlignment="Top" Width="75" DockPanel.Dock="Bottom" HorizontalAlignment="Right" Margin="5,5,0,0" Command="{Binding ClearCommand, Mode=OneWay}"/>

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="0.5*"/>
                <ColumnDefinition Width="0.5*"/>
            </Grid.ColumnDefinitions>
            <GridSplitter Width="5"/>
            <ListView x:Name="lstErrors" Margin="0,0,5,0" 
                      ItemsSource="{Binding Messages}"
                      SelectedItem="{Binding SelectedItem}"
                      SelectionMode="Extended"
                      IsSynchronizedWithCurrentItem="True"
                      view:ListExtenders.AutoScrollToCurrentItem="True"
                      ItemTemplate="{DynamicResource MessageItemTemplate}"
                      HorizontalContentAlignment="Stretch">
                <ListView.ItemContainerStyle>
                    <Style TargetType="{x:Type ListViewItem}">
                        <Setter Property="IsSelected" Value="{Binding Mode=TwoWay, Path=IsSelected}"/>
                    </Style>
                </ListView.ItemContainerStyle>
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="SelectionChanged">
                        <command:EventToCommand Command="{Binding ItemSelectionChangedCommand}"/>
                    </i:EventTrigger>
                    <i:EventTrigger EventName="MouseDoubleClick">
                        <command:EventToCommand Command="{Binding ItemExecuteCommand}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </ListView>
            <TextBox Grid.Column="1" TextWrapping="Wrap" d:LayoutOverrides="Width" Text="{Binding DetailsText}"/>
        </Grid>
    </DockPanel>
</UserControl>